﻿/*
*┌────────────────────────────────────────────────┐
*│　描    述：PushDataSerivce                                                   
*│　作    者： (Jxw)                                             
*│　版    本：1.0     
*│　功能描述：                                          
*│　创建时间：2021/4/20 10:29:54                        
*└────────────────────────────────────────────────┘
*/

using Business;
using Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Utility;

namespace Service
{
    public class PushDataSerivce
    {
        private static PushDataSerivce m_service = null;
        private DataChangeLog m_DataChangeLog = new DataChangeLog(); //数据变化日志数据访问
        private int m_SleepIntervalForDataChangeLog = 1000 * 60 * 60; //休眠间隔 1小时
        private bool m_workSign = true;//线程工作标志


        /// <summary>
        /// 私有构造函数
        /// </summary>
        private PushDataSerivce()
        {

        }

        public static PushDataSerivce service
        {
            get
            {
                if (m_service == null)
                    m_service = new PushDataSerivce();
                return m_service;
            }
        }


        /// <summary>
        /// 数据推送
        /// </summary>
        public void PushWDData()
        {
            while (m_workSign)
            {
                DataTable tempToldInfo = m_DataChangeLog.GetDataChangeTable("TToldInfo");
                if (tempToldInfo != null && tempToldInfo.Rows.Count > 0)
                {
                    WDPushBusiness.PushBusiness.pushPatientResuorceData(tempToldInfo.DefaultView);
                }
              
                Thread.Sleep(AppConfig.UploadTime);//休眠一分钟
            }

        }

        public void ClearDataChangeLog()
        {
            while (true)
            {
                //日志流水改变数据
                m_DataChangeLog.DeleteDataChangeLog();

                Thread.Sleep(m_SleepIntervalForDataChangeLog);
            }
        }



    


        /// <summary>
        /// 定时获取设备绑定信息
        /// </summary>
        public void DeviceBindService()
        {
            //DeviceBindBusiness.DataBusiness.GetDeviceBindInfo();//程序启动初次获取设备绑定信息
            DeviceBindBusiness.DataBusiness.TimerStarttell();//定时获取获取设备绑定信息（一小时获取一次）

        }





        public void StopWork()
        {
            this.m_workSign = false;
        }

       
    }
}
